package com.ruoyi.inventory.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inventory.domain.BizStockCheck;
import com.ruoyi.inventory.service.IBizStockCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存盘点记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/inventory/check")
public class BizStockCheckController extends BaseController
{
    private String prefix = "inventory/check";

    @Autowired
    private IBizStockCheckService bizStockCheckService;

    @RequiresPermissions("inventory:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询库存盘点记录列表
     */
    @RequiresPermissions("inventory:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizStockCheck bizStockCheck)
    {
        startPage();
        List<BizStockCheck> list = bizStockCheckService.selectBizStockCheckList(bizStockCheck);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点记录列表
     */
    @RequiresPermissions("inventory:check:export")
    @Log(title = "库存盘点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizStockCheck bizStockCheck)
    {
        List<BizStockCheck> list = bizStockCheckService.selectBizStockCheckList(bizStockCheck);
        ExcelUtil<BizStockCheck> util = new ExcelUtil<BizStockCheck>(BizStockCheck.class);
        return util.exportExcel(list, "库存盘点记录数据");
    }

    /**
     * 新增库存盘点记录
     */
    @RequiresPermissions("inventory:check:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存盘点记录
     */
    @RequiresPermissions("inventory:check:add")
    @Log(title = "库存盘点记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizStockCheck bizStockCheck)
    {
        return toAjax(bizStockCheckService.insertBizStockCheck(bizStockCheck));
    }

    /**
     * 修改库存盘点记录
     */
    @RequiresPermissions("inventory:check:edit")
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        BizStockCheck bizStockCheck = bizStockCheckService.selectBizStockCheckByCheckId(checkId);
        mmap.put("bizStockCheck", bizStockCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存盘点记录
     */
    @RequiresPermissions("inventory:check:edit")
    @Log(title = "库存盘点记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizStockCheck bizStockCheck)
    {
        return toAjax(bizStockCheckService.updateBizStockCheck(bizStockCheck));
    }

    /**
     * 删除库存盘点记录
     */
    @RequiresPermissions("inventory:check:remove")
    @Log(title = "库存盘点记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizStockCheckService.deleteBizStockCheckByCheckIds(ids));
    }
}
